package com.toy.core.util;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.toy.core.exception.ToyException;

public class HttpResponseUtils {
	
	public static void write(HttpServletResponse response,Object object){
		response.setContentType("text/html;charset=utf-8");
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		try {
			PrintWriter pw = response.getWriter();
			pw.print(object);
			pw.flush();
			pw.close();
		} catch (Exception e) {
			e.printStackTrace();
			throw new ToyException(e);
		}
	}
	
	public static void  writeScripts(HttpServletResponse response,String scripts){
		StringBuffer html = new StringBuffer();
		html.append("<SCRIPT>");
		html.append(scripts);
		html.append("</SCRIPT>");
		write(response, html);
	}
	
}
